Skip to content

Conversation

@sapayth
Copy link
Member

@sapayth sapayth commented Apr 22, 2025

fixes #724 fixes #723

image
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability in displaying trial duration and status information for subscription packs.
    • Refined logic for displaying featured item counts and post counts in subscription dashboards.
    • Enhanced recurring payment checks for subscription packs for more accurate display and processing.
    • Updated trial and billing limit data handling for consistent subscription information display.
  • Style
    • Removed unnecessary trailing space in subscription pack titles for cleaner presentation.

@coderabbitai
Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

This update standardizes the use of meta keys related to trial duration and recurring payment options throughout the subscription-related classes and templates. It replaces direct string comparisons for recurring payment checks with a helper function for improved robustness and changes key references from non-underscored to underscored versions for trial-related metadata. Additionally, conditional logic for displaying featured items and post counts in subscription templates is refined, and a debug log statement is added for recurring payment checks in the frontend account logic.

Changes

Files/Paths Change Summary
class/subscription.php, includes/Admin/Subscription.php Updated trial-related meta key references from non-underscored to underscored versions in subscription data handling.
includes/Frontend/Frontend_Account.php, templates/subscriptions/pack-details.php Replaced recurring payment string comparison with helper function; updated trial duration type key; added debug log; refined billing limit logic.
templates/dashboard/subscription.php Modified display logic for featured item and post counts to check for specific values (-1) instead of non-emptiness or zero only.
templates/subscriptions/pack-details.php Removed trailing space in title output; updated recurring payment check to use helper function.

Assessment against linked issues

Objective Addressed Explanation
Prevent duplicate invoice email receipts (#724) No changes related to invoice email sending logic are present in this PR.
Ensure billing address is retained and displayed correctly in account and invoice PDF (#723) No modifications related to billing address storage or display are included in this PR.

Suggested labels

QA Approved, Ready to Merge

Poem

In fields of code where rabbits hop,
Meta keys now wear an underscore top.
Recurring checks are smarter too,
With helper hops, not just “yes” will do!
Debug logs burrow deep,
While featured counts are theirs to keep.
🐇 Cheers to code that’s neat and bright—
This patch brings logic to the light!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2236d68 and 56c4ed9.

📒 Files selected for processing (1)
  • includes/Admin/Subscription.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Admin/Subscription.php
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
templates/dashboard/subscription.php (1)

16-16: Refine the featured item display condition.

The condition now ensures that the featured item count is only shown when it's unlimited (-1). This provides better clarity for users when viewing their subscription details.

Note: There's a small formatting issue with the indentation that should be fixed.

-             if ( ! empty( $user_sub['total_feature_item'] ) && -1 === $user_sub['total_feature_item'] ) { ?>
+            if ( ! empty( $user_sub['total_feature_item'] ) && -1 === $user_sub['total_feature_item'] ) { ?>
🧰 Tools
🪛 GitHub Check: Run PHPCS inspection

[failure] 16-16:
Closing PHP tag must be on a line by itself


[failure] 16-16:
Line indented incorrectly; expected 3 tabs, found 3 tabs and 1 spaces


[warning] 16-16:
Found precision alignment of 1 spaces.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4853362 and 2236d68.

📒 Files selected for processing (5)
  • class/subscription.php (2 hunks)
  • includes/Admin/Subscription.php (2 hunks)
  • includes/Frontend/Frontend_Account.php (1 hunks)
  • templates/dashboard/subscription.php (2 hunks)
  • templates/subscriptions/pack-details.php (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
templates/subscriptions/pack-details.php (1)
wpuf-functions.php (1)
  • wpuf_is_checkbox_or_toggle_on (5445-5447)
includes/Admin/Subscription.php (2)
class/subscription.php (1)
  • get_cycle_label (914-923)
wpuf-functions.php (1)
  • wpuf_is_checkbox_or_toggle_on (5445-5447)
class/subscription.php (1)
includes/Admin/Subscription.php (1)
  • get_cycle_label (935-944)
🪛 GitHub Check: Run PHPCS inspection
templates/dashboard/subscription.php

[failure] 16-16:
Closing PHP tag must be on a line by itself


[failure] 16-16:
Line indented incorrectly; expected 3 tabs, found 3 tabs and 1 spaces


[warning] 16-16:
Found precision alignment of 1 spaces.

🪛 GitHub Actions: Inspections
class/subscription.php

[error] 1-1: PHP CodeSniffer: Expected 1 space after opening PHP tag; 2 found.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (8)
templates/dashboard/subscription.php (1)

27-27: Improved skip condition for post counts.

The condition now properly skips both zero and unlimited (-1) post counts when iterating through the available posts. This is a logical improvement since both values should be treated similarly in the display context.

templates/subscriptions/pack-details.php (2)

18-18: Code cleanup: Removed trailing space in h3 tag.

This is a minor but welcome formatting improvement.


31-31: Enhanced recurring payment check using helper function.

Replacing the direct string comparison with wpuf_is_checkbox_or_toggle_on() makes the code more robust by handling various representations of "on" states ('yes', 'on', 'true', '1'). This standardizes how checkbox values are evaluated throughout the application.

includes/Frontend/Frontend_Account.php (3)

230-231: Enhanced recurring payment check with debug logging.

The code now uses the wpuf_is_checkbox_or_toggle_on() helper function instead of a direct string comparison for better robustness. The added debug logging will be helpful for troubleshooting subscription-related issues.


237-237: Updated meta key to use standardized format.

The meta key for trial duration type has been updated to use the underscored format (_trial_duration_type), which aligns with WordPress conventions for private meta keys and ensures consistency across the codebase.


239-241: Refined billing limit display condition.

The condition for appending the billing limit description has been improved to only display when the billing limit is not empty and equals -1 (unlimited). This makes the display logic more precise and prevents potential confusion in the UI.

class/subscription.php (2)

394-394: Updated trial duration type meta key to use standardized format.

The code now uses the underscored version of the meta key (_trial_duration_type) which is consistent with the changes in other files and follows WordPress conventions for private meta keys.


958-958: Consistent usage of underscored meta key format.

The code correctly uses the _trial_duration_type meta key in the recurring description formatting, which aligns with the standardization of meta keys across the codebase.

Comment on lines +986 to +990
if ( $billing_amount && wpuf_is_checkbox_or_toggle_on( $pack->meta_value['recurring_pay'] ) && wpuf_is_checkbox_or_toggle_on( $pack->meta_value['_trial_status'] ) ) {
//phpcs:ignore
$duration = _n( $pack->meta_value['trial_duration_type'], $pack->meta_value['trial_duration_type'] . 's', $pack->meta_value['trial_duration'], 'wp-user-frontend' );
$duration = _n( $pack->meta_value['_trial_duration_type'], $pack->meta_value['_trial_duration_type'] . 's', $pack->meta_value['_trial_duration'], 'wp-user-frontend' );
/* translators: %s: trial days */
$trial_des = sprintf( __( 'Trial available for first %1$s %2$s', 'wp-user-frontend' ), $pack->meta_value['trial_duration'], $duration );
$trial_des = sprintf( __( 'Trial available for first %1$s %2$s', 'wp-user-frontend' ), $pack->meta_value['_trial_duration'], $duration );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Standardized trial metadata handling

This change improves code consistency in two ways:

  1. Uses wpuf_is_checkbox_or_toggle_on() for both recurring payment and trial status checks
  2. Properly references underscored trial metadata keys (_trial_duration_type) which aligns with the metadata storage approach throughout the codebase

This standardization helps prevent potential bugs from inconsistent meta key references.

@Rubaiyat-E-Mohammad
Copy link
Contributor

Wrong info showing @sapayth vai
CleanShot 2025-04-22 at 13 51 59

@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added bug needs: dev review This PR needs review by a developer and removed QA In Progress labels Apr 22, 2025
@sapayth
Copy link
Member Author

sapayth commented Apr 23, 2025

Wrong info showing @sapayth vai CleanShot 2025-04-22 at 13 51 59

please have a look now

@sapayth sapayth added needs: testing and removed needs: dev review This PR needs review by a developer labels Apr 23, 2025
@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added needs: dev review This PR needs review by a developer QA Approved This PR is approved by the QA team Ready to Merge This PR is now ready to be merged and removed needs: testing bug needs: dev review This PR needs review by a developer labels Apr 23, 2025
@sapayth sapayth merged commit 74ab233 into weDevsOfficial:develop Apr 23, 2025
1 of 2 checks passed
@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added bug needs: dev review This PR needs review by a developer QA Approved This PR is approved by the QA team Ready to Merge This PR is now ready to be merged and removed QA Approved This PR is approved by the QA team Ready to Merge This PR is now ready to be merged bug needs: dev review This PR needs review by a developer labels Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA Approved This PR is approved by the QA team Ready to Merge This PR is now ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants